package com.developer.platform.application.query;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.developer.platform.application.query.assembler.GroupAssembler;
import com.developer.platform.application.query.dto.GroupDto;
import com.developer.platform.application.query.dto.ResponseModel;
import com.developer.platform.domain.Group;
import com.developer.platform.infrastructure.data.mapper.GroupMapper;
import com.veeker.core.bean.Pageable;
import org.springframework.stereotype.Component;

/**
 * @author ：qiaoliang
 * @date ：2020-12-29
 */
@Component
public class GroupQueryManager {

  private final GroupMapper groupMapper;
  private final GroupAssembler groupAssembler;

  public GroupQueryManager(
      GroupMapper groupMapper,
      GroupAssembler groupAssembler) {
    this.groupMapper = groupMapper;
    this.groupAssembler = groupAssembler;
  }

  public ResponseModel<GroupDto> list(Pageable pageable){
    LambdaQueryWrapper<Group> queryWrapper = new LambdaQueryWrapper<>();
    return groupAssembler.toGroupDtoPage(groupMapper
        .selectPage(new Page<>(pageable.getPageNumber(), pageable.getPageSize()),
            queryWrapper));
  }

}
